
class Login {
	constructor() {
		console.log($.cookie());
		this.init();
	}
}
$.extend(Login.prototype, {
	init: function () {
		$('#validcaptcha').on('click', $.proxy(this.getCaptcha, this));
		$('.loginBtn').on('click', $.proxy(this.melonLogin, this));
	},
	melonLogin: function () {
		let tel = $('#tel').val();
		let password = $('#pwd').val();
		let telActive = $('#cap').val();
		console.log(1);
		$.ajax({
			url: 'http://localhost:8888/phpmelon', data: {
				tel: tel,
				password: password,
				telActive: telActive,
				lfm: 'login'
			},
			success: function (res) {
				console.log(res);
				switch (res) {
					
					case '0': alert('密码或验证码不正确'); break;;
					default: $.cookie('username', res, { expires: 7, path: '/' });alert('登录成功');window.location.href ='http://localhost:8888';break;
				}
			}
		})
	},
	getCaptcha: function () {
		let tel = $('#tel').val();
		$.ajax({
			url: 'http://localhost:8888/phpmelon', data:
			{
				tel: tel,
				lfm: 'captcha'
			},
			success: function (res) {
				console.log(res);
				$('#cap').val(res);
			}
		})
	}
})


new Login();